using System;
using System.Collections.Generic;
using System.Text;
using Acms.AcmsControls.ContentControls.FrontEnd;

namespace Acms.AcmsControls
{
    public class ImageContentControlDisplay : BaseContentControlDisplay<ImageContentControlProperties>
    {
        private AcmsImage image = new AcmsImage();

        protected override void CreateChildControls()
        {
            this.Controls.Add(image);
            base.CreateChildControls();
        }

        protected override void DataBindChildren()
        {
            if(Properties != null)
            {
                image.FileId = Properties.ResourceId;
                image.AlternateText = Properties.AltText;
            }
            image.RenderHeight = this.RenderHeight;
            image.RenderWidth = this.RenderWidth;
        }

        private int renderHeight;
        public int RenderHeight
        {
            get { return renderHeight; }
            set { renderHeight = value; }
        }

        private int renderWidth;
        public int RenderWidth
        {
            get { return renderWidth; }
            set { renderWidth = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (this.image == null || this.image.FileId == null || this.image.FileId == 0)
            {
                this.Visible = false;
            }
        }

        public override bool IsEmpty
        {
            get 
            {
                if (Properties != null && Properties.HasResource())
                {
                    return false;
                }
                else
                {
                    return true;
                }

            }
        }
    }
}
